package com.xm.xmapp.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xm.xmapp.MessageActivity;
import com.xm.xmapp.R;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.myinterface.MainInterFaceAble;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.xm.xmapp.myinterface.MainInterFaceAble.FRESH_CODE;


/**
 * Created by LDW on 2017/7/20.
 */
public class MainBottomFragment extends Fragment {
    MainInterFaceAble mMainInterFaceAble;
    @Bind(R.id.iv_persion)
    ImageView ivPersion;
    @Bind(R.id.iv_loaction)
    ImageView ivLoaction;
    @Bind(R.id.iv_msg)
    ImageView ivMsg;
    @Bind(R.id.saomatext)
    TextView saomatext;
    @Bind(R.id.saoma)
    RelativeLayout saoma;
    @Bind(R.id.iv_fresh)
    ImageView ivFresh;
    private Animation animation; // 动画，大客户刷新按钮，转圈

    public void setmMainInterFaceAble(MainInterFaceAble mMainInterFaceAble) {
        this.mMainInterFaceAble = mMainInterFaceAble;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mainbottom, null, false);
        ButterKnife.bind(this, view);
        animation = AnimationUtils.loadAnimation(getActivity(), R.anim.loading_round);
        animation.setRepeatCount(Animation.INFINITE);
        animation.setRepeatMode(Animation.RESTART);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.iv_persion, R.id.iv_loaction, R.id.iv_msg, R.id.saoma,R.id.iv_fresh})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_persion:
                mMainInterFaceAble.uIChange(MainInterFaceAble.SHOW_DIALOG, null);
                break;
            case R.id.iv_loaction:
                mMainInterFaceAble.uIChange(MainInterFaceAble.GET_LOCTION, null);
                break;
            case R.id.iv_msg:
                Intent intent =  new Intent(MyAppcation.getMyAppcation(), MessageActivity.class);
                startActivity(intent);
                break;
            case R.id.saoma: {
                mMainInterFaceAble.uIChange(MainInterFaceAble.SCAN_CODE, null);
                break;
            }
            case R.id.iv_fresh: {
                mMainInterFaceAble.uIChange(MainInterFaceAble.FRESH_CODE, null);
                break;
            }
        }
    }


    public void setFreshIsVisable(int visible) {
        ivFresh.setVisibility(visible);
    }

    public void startAnimation() {
        ivFresh.startAnimation(animation);
    }

    public void clearAnimation() {
        ivFresh.clearAnimation();
    }

    public void setScanText(String text) {
        saomatext.setText(text);
    }

    public void setScanVisable(int visible) {
        saoma.setVisibility(visible);
    }


    public void setMessageIcon(int iocn) {
        ivMsg.setImageResource(iocn);
    }
}
